package com.huatai.datacenter.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @author Lion
 * @date 2023/4/18  9:25
 */
@Configuration
public class ApiMvcConfiguration implements WebMvcConfigurer {

	@Autowired
	private ApiInterceptor apiInterceptor;

	@Bean
	ContextHolderInterceptor contextInterceptor() {
		return new ContextHolderInterceptor();
	}

	/**
	 * 注册拦截器
	 * 可注册多个拦截器，多个拦截器组成一个拦截器链
	 *
	 * @param registry
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 注册拦截器
		registry.addInterceptor(apiInterceptor).addPathPatterns("/open-api/**");
		InterceptorRegistration ir = registry.addInterceptor(contextInterceptor());
		// 配置拦截的路径
		ir.addPathPatterns("/**");
	}

}
